import 'package:flutter/material.dart';

import '../../../core/app_initializer.dart';

class ThemeController extends ChangeNotifier {
  static const _key = 'app_theme_mode';
  ThemeMode _mode = ThemeMode.system;

  ThemeMode get mode => _mode;

  ThemeMode get themeMode {
    switch (_mode) {
      case ThemeMode.light:
        return ThemeMode.light;
      case ThemeMode.dark:
        return ThemeMode.dark;
      case ThemeMode.system:
      default:
        return ThemeMode.system;
    }
  }

  Future<void> loadTheme() async {
    final value = AppInitializer.prefs.getInt(_key) ?? 0;
    _mode = ThemeMode.values[value];
    notifyListeners();
  }

  Future<void> updateTheme(ThemeMode newMode) async {
    _mode = newMode;
    await AppInitializer.prefs.setInt(_key, newMode.index);
    notifyListeners();
  }
}
